<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<form action="" method="post">
		<input type="file" name="file" id="demo">
		<input type="button" value="上传" id="upload">
	</form>
	<script type="text/javascript">
	
	var upload = document.getElementById('upload');
	upload.onclick = function(){
		var demo = document.getElementById('demo');
		var file = demo.files[0];
		console.log(file);
		const SLICESIZE = 1204*1024;
		var size = file.size;
		var start = 0;
		var end = 0;
		while(start<size){
			start = end;
			end  = start + SLICESIZE;
			var xhr =  new XMLHttpRequest();
			var fd = new FormData();
			var part = file.slice(start,end);

			fd.append('file',part);
			// 这里添加个post过去的参数，适当的可以添加些唯一标识符用于标记不同的文件上传，防止同一时间同一个文件名上传，出现冲突覆盖。
			fd.append('username',encodeURI(file.name));
			xhr.open('POST','ajax.php',false);
			xhr.send(fd);
		}
	}

	</script>
</body>
</html>